﻿using System;

namespace WiMo.Games
{
    public struct Color
    {
        private byte _a, _r, _g, _b;
        public Color(Color c, byte a)
        {
            _r = c.R;
            _g = c.G;
            _b = c.B;
            _a = a;
        }

        public Color(byte r, byte g, byte b)
        {
            _a = 0xff;
            _r = r;
            _g = g;
            _b = b;
        }

        public Color(byte r, byte g, byte b, byte a)
        {
            _a = a;
            _r = r;
            _g = g;
            _b = b;
        }

        public Color GetInverted()
        {
            return new Color(Convert.ToByte(0xFF - _r), Convert.ToByte(0xFF - _g), Convert.ToByte(0xFF - _b));
        }

        public byte A { get { return _a; } set { _a = value; } }
        public byte R { get { return _r; } }
        public byte G { get { return _g; } }
        public byte B { get { return _b; } }

        public static Color Red { get { return new Color(0xFF, 0x00, 0x00); } }
        public static Color Navy { get { return new Color(0x23, 0x23, 0x8e); } }
        public static Color Silver { get { return new Color(0xE6, 0xE8, 0xFA); } }
        public static Color Yellow { get { return new Color(0xFF, 0xFF, 0x00); } }
        public static Color LightYellow { get { return new Color(0xFF, 0xFF, 0xE0); } }
        public static Color Green { get { return new Color(0x00, 0xFF, 0x00); } }
        public static Color Blue { get { return new Color(0x00, 0x00, 0xFF); } }
        public static Color Black { get { return new Color(0x00, 0x00, 0x00); } }
        public static Color White { get { return new Color(0xFF, 0xFF, 0xFF); } }
        public static Color LightGray { get { return new Color(0xA8, 0xA8, 0xA8); } }
        public static Color LightBlue { get { return new Color(0xC0, 0xD9, 0xD9); } }
        public static Color Azure { get { return new Color(0x00, 0x7F, 0xFF); } }
        public static Color Transparent { get { return new Color(0xFF, 0xFF, 0xFF, 0x00); } }
        public static Color SpringGreen { get { return new Color(0x00, 0xFF, 0x7F); } }
        public static Color SummerySky { get { return new Color(0x38, 0xB0, 0xDE); } }
        public static Color Tan { get { return new Color(0xDB, 0x93, 0x70); } }
        public static Color Grey { get { return new Color(0xC0, 0xC0, 0xC0); } }
        public static Color CornFlowerBlue { get { return new Color(0x64, 0x95, 0xED); } }

        public static bool operator ==(Color color1, Color color2)
        {
            if (color1._a != color2._a)
                return false;

            if (color1._r != color2._r)
                return false;

            if (color1._g != color2._g)
                return false;

            if (color1._b != color2._b)
                return false;

            return true;
        }

        public static Color operator /(Color color1, int div)
        {
            return new Color((byte)(color1.A / div), (byte)(color1.G / div), (byte)(color1.B / div));
        }


        public static Color operator + (Color color1, Color color2)
        {
            return new Color((byte)(color1.A + color1.A), (byte)(color1.G + color2.G), (byte)(color1.B + color2.B));
        }

        public static bool operator != (Color color1, Color color2)
        {
            return !(color1 == color2);
        }

        public override bool Equals(object obj)
        {
            return (this == (Color)obj);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
